/*
 * Copyright (c) 2017. 深圳一七科技. All rights reserved.
 */

package com.yiqi.liebang.feature.order.presenter;

import com.yiqi.liebang.entity.bo.OrderBo;
import com.yiqi.liebang.entity.bo.PageBo;
import com.yiqi.liebang.entity.bo.TopicOrderBo;
import com.yiqi.liebang.feature.order.contract.OrderContract;
import com.yiqi.liebang.feature.order.contract.TopicContract;
import com.yiqi.liebang.feature.order.dependencies.order.DaggerOrderPresenterComponent;
import com.yiqi.liebang.feature.order.dependencies.topic.DaggerTopicOrderPresenterComponent;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class TopicOrderPresenter implements TopicContract.Presenter {

    private TopicContract.View mView;

    @Inject

    TopicContract.Model mModel;


    public TopicOrderPresenter(TopicContract.View mView) {
        this.mView = mView;
        DaggerTopicOrderPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }



    @Override
    public void getTopicOrderList(int type, int pageIndex, int pageSize) {
        mModel.getTopicOrderList(new PageBo(type,pageIndex, pageSize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TopicOrderBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<TopicOrderBo> couponBoPageData) {
                if (couponBoPageData!=null&&couponBoPageData.size()>0){
                    mView.showTopicOrderListSuccess(couponBoPageData);
                }else {
                    mView.showOrderListEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showTopicOrderListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getTopicOrderListMore(int type, int pageIndex, int pageSize) {
        mModel.getTopicOrderList(new PageBo(type,pageIndex, pageSize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TopicOrderBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<TopicOrderBo> couponBoPageData) {
                mView.showTopicOrderListMoreSuccess(couponBoPageData);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showTopicOrderListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }
}
